package Student;

import java.util.Random;
import java.util.ArrayList;

public class RandomSelector {
    private ClassManager classManager;
    private GroupManager groupManager;
    private StudentManager studentManager;

    public RandomSelector(ClassManager classManager, GroupManager groupManager, StudentManager studentManager) {
        this.classManager = classManager;
        this.groupManager = groupManager;
        this.studentManager = studentManager;
    }

    public ClassManager getClassManager() {
        return classManager;
    }

    public void setClassManager(ClassManager classManager) {
        this.classManager = classManager;
    }

    public GroupManager getGroupManager() {
        return groupManager;
    }

    public void setGroupManager(GroupManager groupManager) {
        this.groupManager = groupManager;
    }

    public StudentManager getStudentManager() {
        return studentManager;
    }

    public void setStudentManager(StudentManager studentManager) {
        this.studentManager = studentManager;
    }

    public String selectRandomGroup() {
        if (groupManager.getGroups().isEmpty()) {
            return "没有小组可供随机抽取";
        }
        Random random = new Random();
        int index = random.nextInt(groupManager.getGroups().size());
        return groupManager.getGroups().get(index);
    }

    public String selectRandomStudent(String className) {
        ArrayList<Student> eligibleStudents = new ArrayList<>();
        for (Student student : studentManager.getStudents()) {
            if (student.getClassName().equalsIgnoreCase(className)) {
                eligibleStudents.add(student);
            }
        }
        if (eligibleStudents.isEmpty()) {
            return "没有此班级的学生可供随机抽取";
        }
        Random random = new Random();
        int index = random.nextInt(eligibleStudents.size());
        return eligibleStudents.get(index).getName();
    }
}
